function RequestBean(url, success) {
    this.url = url;
    this.success = success;
    this.header = {
        'content-type': 'application/json' // 默认值
    };
    this.data = null;
    this.toString = function () {
        let str = url;
        let param = '';
        var data = this.data;
        if (data !== null) {
            for (var key in data) {
                param += key + "=" + data[key].toJson() + '&';
            }
            str += '?' + param.substr(0, param.length - 1);
        }
        return str;
    }
}


function Server(configIp, dataIp) {
    //登录
    this.getLoginData = function (userName, password, success) {
        var url = configIp + '/WaterMonitor/android/move/data/getLoginData';
        var request = new RequestBean(url, success);
        request.data = {
            subject: '0',
            userName: userName,
            password: password
        };
        httpGet(request);
    };

    //初始化数据
    this.getInitData = function (success) {
        var url = configIp + '/WaterMonitor/android/move/data/getInitData';
        var request = new RequestBean(url, success);
        request.data = {
            subject: '0',
            'userId': getApp().userId
        };
        httpGet(request);
    };

    //主界面实时数据
    this.getMultiFactoryRuntimeData = function (factoryList, success) {
        let url = configIp + '/WaterMonitor/android/move/data/getMultiFactoryRuntimeData';
        var request = new RequestBean(url, success);
        request.data = {
            subject: '0',
            'userId': getApp().userId,
            factoryList: factoryList
        };
        httpGet(request);
    };

    function httpGet(requestBean) {
        requestBean.method = 'GET';
        wx.request(requestBean);
        console.log(requestBean.toString());
    }

    function httpPost(requestBean) {
        requestBean.method = 'POST';
        wx.request(requestBean);
        console.log(requestBean.toString());
    }
}

module.exports = new Server('http://192.168.1.71:3005', 'http://192.168.1.83:8081');
